home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / tnos / tnos100s / ripdump.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-22  |  1.2 KB  |  72 lines

  1. /* RIP packet tracing
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  */
  4. #include "global.h"
  5. #include "config.h"
  6. #include "mbuf.h"
  7. #include "netuser.h"
  8. #include "timer.h"
  9. #include "rip.h"
  10. #include "trace.h"
  11.  
  12. #ifdef TNOS_68K
  13. #define fprintf traceprintf
  14. #endif
  15.  
  16. void
  17. rip_dump(fp,bpp)
  18. FILE *fp;
  19. struct mbuf **bpp;
  20. {
  21.     struct rip_route entry;
  22.     int i;
  23.     int cmd,version;
  24.     int16 len;
  25.     
  26.     fprintf(fp,"RIP: ");
  27.     cmd = PULLCHAR(bpp);
  28.     version = PULLCHAR(bpp);
  29.     switch(cmd){
  30.     case RIPCMD_REQUEST:
  31.         fprintf(fp,"REQUEST");
  32.         break;
  33.     case RIPCMD_RESPONSE:
  34.         fprintf(fp,"RESPONSE");
  35.         break;
  36.     default:
  37.         fprintf(fp," cmd %u",cmd);
  38.         break;
  39.     }
  40.  
  41.     pull16(bpp);    /* remove one word of padding */
  42.  
  43.     len = len_p(*bpp);
  44.     fprintf(fp," vers %u entries %u:\n",version,len / RIPROUTE);
  45.  
  46.     i = 0;
  47.     while(len >= RIPROUTE){
  48.         /* Pull an entry off the packet */
  49.         pullentry(&entry,bpp);
  50.         len -= RIPROUTE;
  51.  
  52.         if(entry.addr_fam != RIP_IPFAM) {
  53.             /* Skip non-IP addresses */
  54.             continue;
  55.         }
  56.         fprintf(fp,"%-16s%-3u ",inet_ntoa(entry.target),entry.metric);
  57.         if((++i % 3) == 0){
  58. #ifdef TNOS_68K
  59.             fprintf (fp, "\n");
  60. #else
  61.             putc('\n',fp);
  62. #endif
  63.         }
  64.     }
  65.     if((i % 3) != 0)
  66. #ifdef TNOS_68K
  67.         fprintf (fp, "\n");
  68. #else
  69.         putc('\n',fp);
  70. #endif
  71. }
  72.